﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using ConsolidationTool.Common;

namespace ConsolidationTool.WebParts.Flash_Input.Flash_Input_SCS.SCSDisplayForm
{
    public partial class SCSDisplayFormUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SetValueToYTDLastMonth();
        }

        void SetValueToYTDLastMonth()
        {
            LabelSV01030100.Text = GetYTDLastMonthValue("SV01030100");
            LabelSV01030101.Text = GetYTDLastMonthValue("SV01030101");
            LabelSV01030102.Text = GetYTDLastMonthValue("SV01030102");
            LabelSV01030103.Text = GetYTDLastMonthValue("SV01030103");
            //LabelSV01030104.Text = GetYTDLastMonthValue("SV01030104");
            LabelSV01040100.Text = GetYTDLastMonthValue("SV01040100");
            LabelSV01050100.Text = GetYTDLastMonthValue("SV01050100");
            LabelSV01050101.Text = GetYTDLastMonthValue("SV01050101");
            LabelSV01050102.Text = GetYTDLastMonthValue("SV01050102");
            LabelSV01050103.Text = GetYTDLastMonthValue("SV01050103");
            LabelSV01060100.Text = GetYTDLastMonthValue("SV01060100");
        }

        string GetYTDLastMonthValue(string fieldName)
        {

            string rst = "0";

            DataTable dt = Common.BusinessService.GetSCSYTDLastMonthData(FormFieldYear.ItemFieldValue.ToString(), FormFieldMonth.ItemFieldValue.ToString(), FormFieldCoCd.ItemFieldValue.ToString());
            if (dt != null)
                rst = dt.Compute("SUM(" + fieldName + ")", "").ToString();
            if (rst == null || rst == "")
            {
                rst = "0";
            }
            return rst;
        }
    }
}
